home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / bbedit-30-dev-kit.hqx / BBEdit 3.0 Extension Dev. Kit / Fat Extensions / BuildEducate.R < prev    next >
Encoding:
Text File  |  1994-07-16  |  3.5 KB  |  110 lines

  1. /*
  2.     Use the 'sdes' template to define a “safe fat resource” which 
  3.     contains both 68K and PowerPC code. A safe fat resource starts
  4.     with 68K code which is executed the first time the resource
  5.     is called. This code determines if MixedMode is present. If
  6.     so, a routine descriptor is moved to the beginning of the
  7.     resource. If not, a branch instruction to the 68K portion
  8.     of the code is placed at the beginning of the resource. 
  9.     Therefore, the first time the resource is executed, there 
  10.     is some overhead incurred. However, subsequent calls 
  11.     will be fast.
  12.     
  13.     Note: This template cannot currently be used for resources
  14.     containing code with register-based calling conventions
  15.     because the 68K code at the beginning of the resource
  16.     uses D0, A0, and A1.
  17.     
  18. */
  19.     
  20. #include "MixedMode.r"
  21.  
  22. #define ExtensionUPPInfo $000003C0
  23.  
  24. include "EducateQuotes.Rsrc";
  25.  
  26. type 'BBXT' as 'sdes';
  27.  
  28. resource 'BBXT' (128, "Educate Quotes") {
  29.     ExtensionUPPInfo,                        // 68K ProcInfo
  30.     ExtensionUPPInfo,                        // PowerPC ProcInfo
  31.     $$Resource("Educate/68K", 'BBXT', 128),    // Specify name, type, and ID of resource
  32.                                             //   containing 68k code
  33.     $$Resource("Educate/PPC", 'BBXT', 128)    // Specify name, type, and ID of resource
  34.                                             //   containing a pef container
  35. };
  36.  
  37. /*  Safe Fat Resources  */
  38. type 'sdes' { 
  39. Top:
  40.     hex string    = 
  41.         $"303C A89F"    //     SafeFatRsrc        MOVE.W        #_Unimplemented, D0
  42.         $"A746"            //                     _GetToolBoxTrapAddress
  43.         $"2F08"            //                     MOVE.L        A0, -(SP)
  44.         $"303C AAFE"    //                     MOVE.W        #_MixedModeMagic, D0 
  45.         $"A746"            //                     _GetToolBoxTrapAddress
  46.         $"B1DF"            //                     CMPA.L        (SP)+, A0                // Is MM installed?
  47.         $"661A"            //                     BNE.S        InstallPPCCode
  48.         $"41FA FFEC"    // Install68KCode    LEA            SafeFatRsrc, A0
  49.         $"30FC 6000"    //                    MOVE.W        #$6000, (A0)+            // Generate a BRA instruction
  50.         $"43FA 001E"    //                    LEA            FatRD, A1
  51.         $"2029 0014"    //                    MOVE.L        20(A1), D0                // Get 68K code offset
  52.         $"5580"            //                    SUBQ.L        #2, D0
  53.         $"3080"            //                    MOVE.W        D0, (A0)                // Fill in the second word of the BRA
  54.         $"7001 A198"    //                    _FlushInstructionCache
  55.         $"60D4"            //                    BRA.S        SafeFatRsrc
  56.         $"43FA FFD2"    // InstallPPCCode    LEA            SafeFatRsrc, A1
  57.         $"41FA 0008"    //                    LEA            FatRD, A0
  58.         $"7034"            //                    MOVE.L        #52, D0
  59.         $"A02E"            //                    _BlockMove                            // Move R.D. to top of rsrc
  60.         $"60C6";        //                     BRA            SafeFatRsrc
  61.                         // FatRD            // The fat routine descriptor follows
  62.  
  63.     /* Routine Descriptor */
  64.     GoMixedModeTrapType             = _MixedModeMagic;
  65.     VersionType                        = kRoutineDescriptorVersion;
  66.     fill bit [7];
  67.     SelectorsAreIndexableType        = FALSE;
  68.     Reserved1Type;
  69.     Reserved2Type;
  70.     SelectorInfoType                = 0;
  71.     RoutineCountType                = 1;
  72.  
  73.     /* Routine Record */
  74.     ProcInfoType;
  75.     Reserved3Type;
  76.     ISAType                            = kM68kISA;
  77.     fill bit [11];
  78.     RoutineIsDispatchedDefaultType     = FALSE;
  79.     DontPassSelectorType            = FALSE;
  80.     UseNativeISAType                = TRUE;
  81.     FragmentNeedsPreparingType        = FALSE;
  82.     ProcDescriptorIsRelativeType    = TRUE;
  83.     ProcDescriptorType                = (BeginningOf68KCode-Top) / 8;
  84.     Reserved4Type;
  85.     SelectorType                    = 0;
  86.  
  87.     /* PowerPC Routine Record 1 */
  88.     ProcInfoType;
  89.     Reserved3Type;
  90.     ISAType    = kPowerPCISA;
  91.     fill bit [11];
  92.     RoutineIsDispatchedDefaultType     = FALSE;
  93.     DontPassSelectorType             = FALSE;
  94.     UseNativeISAType                 = TRUE;
  95.     FragmentNeedsPreparingType        = TRUE;
  96.     ProcDescriptorIsRelativeType    = TRUE;
  97.     ProcDescriptorType                 = (BeginningOfPowerPCCode-Top) / 8;
  98.     Reserved4Type;
  99.     SelectorType                     = 0;
  100.     Align LONG;
  101.  
  102. BeginningOf68KCode:
  103.     hex string;        // The 68k code starts here
  104.  
  105.     Align LONG;
  106.  
  107. BeginningOfPowerPCCode:
  108.     hex string;        // The PEF container starts here
  109. };
  110.